﻿using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Mvc;
using YBBEST.Office365Portal.Core;

namespace YBBEST.Office365Portal.MvcWebRole.Controllers
{
    public class CopyController : Controller
    {
        private readonly ICopyRepository copyRepository;

        public CopyController(ICopyRepository copyRepository)
        {
            this.copyRepository = copyRepository;
        }

        [HttpPost]
        public ActionResult Upload(HttpPostedFileBase fileBase,string ListTitle)
        {
            byte[] bytes;
            using (var stream = fileBase.InputStream)
            {
                bytes=new byte[stream.Length];
                stream.Read(bytes, 0, (int) stream.Length);
            }
            var name = Path.GetFileName(fileBase.FileName);
            copyRepository.UpLoadFile(name, ListTitle, bytes);
            return RedirectToAction("Index", "List");
        }
    }
}